package com.snap.vseries.bean;

import android.util.SparseArray;

import com.snap.vseries.AppConfig;
import com.snap.vseries.analyze.AlgoParams;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import io.protostuff.Tag;

/**
 * 序列化到文件中的实验数据实体类，包含实验运行数据
 * 使用proto buf的变种 proto stuff 序列化
 * 优点：跨平台，快速，半加密形式
 * <p>
 * tag注解的序号就是 proto buf 中的id
 * 1-15是频率出现高的字段，要做一些预留
 * 16开始就随意了
 * <p>
 * 注意点：
 * 1.每个字段都要加tag 注解
 * 2.新增字段 序号累加下去
 * 3.删除字段用@Deprecated 标记
 * 4.不序列化的字段用 transient关键字
 */
public class ExpInfo implements Serializable {
    /**
     * 是否为模板
     */
    @Tag(1)
    private boolean isTemplate;
    /**
     * 实验名
     */
    @Tag(2)
    private String name;
    /**
     * 实验开始时间
     */
    @Tag(3)
    private long startTime;
    /**
     * 实验结束时间
     */
    @Tag(4)
    private long endTime;
    /**
     * 实验状态：-1尚未开始，00运行中，01自然正常完成，02手动停止完成，03异常终止
     */
    @Tag(5)
    private int state = -1;
    /**
     * 运行过的所有段的循环次数
     */
    @Tag(6)
    private int runCycle;
    /**
     * 样本信息样本信息
     */
    @Tag(7)
    private HoleInfo holeInfo;

    /**
     * 实验程序
     */
    @Tag(9)
    private List<ProgramStage> program;
    /**
     * 所有温度数据 包含 n路tec温度， 1路顶盖温度， 1路环境温度
     */
    @Tag(10)
    private SparseArray<List<TempBean>> tempData;
    /**
     * 是否分析
     */
    @Tag(11)
    private boolean isAnalyzed = false;
    /**
     * 异常终止下 异常码
     */
    @Tag(12)
    private int exceptionCode;
    /**
     * 模板的附加简要说明
     */
    @Tag(13)
    private String description;

    /**
     * 样本名称
     */
    @Tag(15)
    private String sampleName;
    /**
     * 检测项目
     */
    @Tag(16)
    private String testProject;

    /**
     * 所有荧光数据 包含 三路数据：展示(倍率+修复下跌)、原始、倍率
     * 每路数据包含4个通道
     */
    @Tag(20)
    private SparseArray<List<LightBean>> lightData;
    /***
     * 所有溶解数据
     */
    @Tag(19)
    private SparseArray<List<LightBean>> meltData;
    /**
     * 用户自定义通道名称
     */
    @Tag(21)
    private String famName;
    @Tag(22)
    private String vicName;
    @Tag(23)
    private String roxName;
    @Tag(24)
    private String cy5Name;
    @Tag(25)
    private double[] crosstalk;//上次分析使用的串扰参数

    @Tag(28)
    private int finishCause = -1;
    @Tag(29)
    private List<ProcessBean> processData;


    @Tag(40)
    private int experimentType;//实验类型  0定性  1定量  2熔解
    @Tag(41)
    private ProgramMeltStage programMeltStage;
    @Tag(42)
    private List<AnalysisProtocol> protocols;
    @Tag(43)
    private AlgoParams algoParams;
    @Tag(44)
    private String deviceTag;

    //////////////////////    @Deprecated    @Deprecated    @Deprecated///////////////////////////
    /**
     * 分析方法  0自动 1手动
     */
    @Deprecated
    @Tag(8)
    private int analyzeType;
    /**
     * 阈值线的值（手动分析时会用到）//todo 有疑问的是阈值线是一条 还是每个通道一条
     */
    @Deprecated
    @Tag(17)
    private double thresholdValue = 0.1;
    /**
     * 不确定这个参数要不要
     */
    @Deprecated
    @Tag(14)
    private SparseArray<float[]> fitDataMap;

    public String getDeviceTag() {
        return deviceTag;
    }

    public void setDeviceTag(String deviceTag) {
        this.deviceTag = deviceTag;
    }

    public ProgramMeltStage getProgramMeltStage() {
        return programMeltStage;
    }

    public void setProgramMeltStage(ProgramMeltStage programMeltStage) {
        this.programMeltStage = programMeltStage;
    }

    public int getExperimentType() {
        return experimentType;
    }

    public void setExperimentType(int experimentType) {
        this.experimentType = experimentType;
    }

    public List<AnalysisProtocol> getProtocols() {
        return protocols;
    }

    public void setProtocols(List<AnalysisProtocol> protocols) {
        this.protocols = protocols;
    }

    public AlgoParams getAlgoParams() {
        return algoParams;
    }

    public void setAlgoParams(AlgoParams algoParams) {
        this.algoParams = algoParams;
    }

    public void fillNecessary() {
        if (protocols == null) {
            protocols = new ArrayList<>();
            for (int i = 0; i < AppConfig.TOTAL_CHANNEL_COUNT; i++) {
                protocols.add(new AnalysisProtocol());
            }
        }
        if (algoParams == null) {
            algoParams = new AlgoParams();
        }
        if (crosstalk == null) {
            crosstalk = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
        }
    }

    public List<ProcessBean> getProcessData() {
        return processData;
    }

    public void setProcessData(List<ProcessBean> processData) {
        this.processData = processData;
    }

    public int getFinishCause() {
        return finishCause;
    }

    public void setFinishCause(int finishCause) {
        this.finishCause = finishCause;
    }

    public SparseArray<List<LightBean>> getMeltData() {
        return meltData;
    }

    public void setMeltData(SparseArray<List<LightBean>> meltData) {
        this.meltData = meltData;
    }

    public ExpInfo() {
    }

    public String getFamName() {
        return famName;
    }

    public void setFamName(String famName) {
        this.famName = famName;
    }

    public String getVicName() {
        return vicName;
    }

    public void setVicName(String vicName) {
        this.vicName = vicName;
    }

    public String getRoxName() {
        return roxName;
    }

    public void setRoxName(String roxName) {
        this.roxName = roxName;
    }

    public String getCy5Name() {
        return cy5Name;
    }

    public void setCy5Name(String cy5Name) {
        this.cy5Name = cy5Name;
    }

    public double[] getCrosstalk() {
        return crosstalk;
    }

    public void setCrosstalk(double[] crosstalk) {
        this.crosstalk = crosstalk;
    }

    public boolean isTemplate() {
        return isTemplate;
    }

    public void setTemplate(boolean template) {
        isTemplate = template;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public int getRunCycle() {
        return runCycle;
    }

    public void setRunCycle(int runCycle) {
        this.runCycle = runCycle;
    }

    public HoleInfo getHoleInfo() {
        return holeInfo;
    }

    public void setHoleInfo(HoleInfo holeInfo) {
        this.holeInfo = holeInfo;
    }

    public List<ProgramStage> getProgram() {
        return program;
    }

    public void setProgram(List<ProgramStage> program) {
        this.program = program;
    }

    public boolean isAnalyzed() {
        return isAnalyzed;
    }

    public void setAnalyzed(boolean analyzed) {
        isAnalyzed = analyzed;
    }

    public int getExceptionCode() {
        return exceptionCode;
    }

    public void setExceptionCode(int exceptionCode) {
        this.exceptionCode = exceptionCode;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSampleName() {
        return sampleName;
    }

    public void setSampleName(String sampleName) {
        this.sampleName = sampleName;
    }

    public String getTestProject() {
        return testProject;
    }

    public void setTestProject(String testProject) {
        this.testProject = testProject;
    }

    public SparseArray<List<TempBean>> getTempData() {
        return tempData;
    }

    public void setTempData(SparseArray<List<TempBean>> tempData) {
        this.tempData = tempData;
    }

    public SparseArray<List<LightBean>> getLightData() {
        return lightData;
    }

    public void setLightData(SparseArray<List<LightBean>> lightData) {
        this.lightData = lightData;
    }
}
